package nl.boektrust.btsoep.client;

import java.util.Date;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.datepicker.client.DatePicker;

public class EditBookVerticalPanelSimpleDate extends EditBookVerticalPanel implements ValueChangeHandler<Date> {
	DatePicker theDatePicker = new DatePicker();
	Date value;
	EditBookDialog parentDialog;

	
	
	public EditBookVerticalPanelSimpleDate(String label, EditBookDialog parentDialog) {
		super(label, (Date)null, false);
		theDatePicker = new DatePicker();		
		theDatePicker.addValueChangeHandler(this);
		this.setValue(value);
		editPanel.add(theDatePicker);
		this.parentDialog = parentDialog;
		this.setToDisplayMode();
	}
	
	public void setValue(Date d) {
		if (d != null) {
			value = d;
			theDatePicker.setValue((Date)value);
			theLabel.setText(this.value.toString());
		} else {
			theLabel.setText("nog niet ingevuld");
		}		
	}
	
	public EditBookVerticalPanelSimpleDate() {
		this("", null);
	}
	
	public Date getDateValue() {
		return value;
	}
	

/*	public void onClick(ClickEvent event) {
		if ((Label)event.getSource() == theLabel) {
			this.toggleEditMode();
		}
		// TODO Auto-generated method stub
		
	}*/

	public void onValueChange(ValueChangeEvent<Date> event) {
		this.setValue(theDatePicker.getValue());
		if (parentDialog != null) parentDialog.panelHasChanged();
		this.setToDisplayMode();
		// TODO Auto-generated method stub
		
	}

}
